package com.coocaa.ops.plus.dashboard.v1.codegen.handler;

import com.coocaa.ops.plus.dashboard.v1.codegen.model.CodeGenConfigModel;
import com.coocaa.ops.plus.dashboard.v1.codegen.validator.CodeGenValidator;
import lombok.experimental.UtilityClass;

import javax.servlet.http.HttpServletRequest;
import java.io.File;

/**
 * @author bijiahao
 * @description
 * @date 2020/11/5 16:06
 */
@UtilityClass
public class CodeGenDataHandler {

    /**
     * 代码生成之前的处理
     *
     * @param codeGenConfigModel
     */
    public static void handleBeforeCodeGen(CodeGenConfigModel codeGenConfigModel, HttpServletRequest request) throws Exception{
        boolean isUseProjectPath = CodeGenValidator.isUseProjectPath(codeGenConfigModel);
        if (isUseProjectPath) {
            //使用项目路径
            String path = getProjectPath(request);
            codeGenConfigModel.setOutputDir(path);
        }
    }

    private static String getProjectPath(HttpServletRequest request) throws Exception {
        // 参数为空
        File directory = new File("");
        String courseFile = directory.getCanonicalPath();
        return courseFile;
    }

}
